<template>
  <div class="head">
    <div class="title">查询条件</div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form ref="form" style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;" :model="form" label-width="80px">
            <div style="display: flex;flex-wrap: wrap;">
              <el-form-item style="margin-left: 0;" class="text" label="网点">
                <el-input :disabled="true" style="height: 36px;" class="input" placeholder="辽宁盘锦公司(124000)" />
              </el-form-item>
              <el-form-item label="">
                <el-select v-model="form.timeType" placeholder="请选择" class="text" style="width: 120px">
                  <el-option label="业务日期" value="1" />
                  <el-option label="记账日期" value="2" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="">
                <el-date-picker v-model="value1" type="daterange" value-format="yyyy-MM-dd" class="input1" range-separator="至" start-placeholder="开始月份" end-placeholder="结束月份" @change="changeTime" />
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button type="primary" @click="Query">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form ref="form" style="text-align: right;" :model="form" label-width="80px">
            <div>
              <el-form-item>
                <el-button><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <elltable :loading="loading" :data="tableData" :th="th">
          <template v-slot:before-columns>
            <el-table-column v-if="tableData.length>0" type="index" :index="indexMethod" width="50" />
          </template>

        </elltable>
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end;margin: 0;">
            <pagination background :current-page="form.pageDate.pageNum" :page-size="form.pageDate.pageSize" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
          </div>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { BalanceInquiryApi } from '@/api/HqFinancePanel'

export default {

  components: {},
  data() {
    return {
      loading: false,
      value1: [],
      form: {
        endTime: '',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: '',
        timeType: ''
      },
      tableData: [],
      total: 0, // 总数
      th: []
    }
  },

  computed: {},

  created() { },

  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.Query()
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.Query()
    },
    // 序号
    indexMethod(index) {
      return index * 1 + 1
    },
    // 选择时间
    changeTime() {
      if (this.value1 != null) {
        this.form.startTime = this.value1[0]
        this.form.endTime = this.value1[1]
      }
    },
    // 查询
    async Query() {
      this.loading = true
      const res = await BalanceInquiryApi(this.form)
      console.log('查询', res)
      this.loading = false

      if (res.code === 200) {
        this.tableData = res.data.list.data
        this.total = res.data.list.total
        this.th = res.data.fields
      } else {
        this.tableData = []
        this.total = 0
        this.th = []
      }
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate') {
          this.form[key] = ''
        }
      })
      this.tableData = []
      this.th = []
      this.value1 = []
      this.total = 0
    }
  }
}

</script>
<style
  scoped
  lang="scss"
>
.my-pagination .el-pagination__prev-btn {
  background-color: blue;
  color: red;
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  // display: flex;
  // justify-content: space-between;
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    // margin-left: 52px;
    .input {
      width: 286px;
      height: 40px;
      background: #ffffff;
      border-radius: 4px;
    }

    .input1 {
      width: 408px;
      height: 40px;
      background: #ffffff;
      border-radius: 4px;
      margin-left: -70px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
